package CCRMClient.GUI;

import javax.swing.JPanel;

import java.awt.CardLayout;
import java.awt.Color;

import javax.swing.border.LineBorder;
import javax.swing.JLabel;

import java.awt.Font;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.JButton;

import CCRMClient.ClientStart;
import Common.SERVER_COMMANDS;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.IOException;

/**
 * This class reachable only to Marketing Manager, for doing actions on marketing templates
 * @author AL
 *
 */
public class TemplateMarketingManagerScreen extends JPanel 
{
	
	private JLabel lblTempMarketingManagerManagment;
	private JLabel lblMarketingManager;
	private JButton btnAudienceForTemp;
	private JButton btnUpdateTemp;
	private JButton btnChangeTempStatus;
	private JButton btnBack;
	

	/**
	 * Create the panel.
	 *
	 */
	public TemplateMarketingManagerScreen() 
	{
		
		initialize();
	}
	
	private void initialize() 
	{
		setSize(451, 328);
		setBorder(new LineBorder(new Color(0, 0, 0)));
		setBackground(Color.WHITE);
		setLayout(null);
		add(getLblTempMarketingManagerManagment());
		add(getLblMarketingManager() );
		add(getBtnAudienceForTemp());
		add(getBtnUpdateTemp());
		add(getBtnChangeTempStatus());
		add(getBtnBack());
	}

	JLabel getLblTempMarketingManagerManagment() 
	{
		if (lblTempMarketingManagerManagment == null) 
		{
			lblTempMarketingManagerManagment = new JLabel("Marketing Template Management");
			lblTempMarketingManagerManagment.setHorizontalAlignment(SwingConstants.CENTER);
			lblTempMarketingManagerManagment.setForeground(Color.RED);
			lblTempMarketingManagerManagment.setFont(new Font("David", Font.BOLD, 26));
			lblTempMarketingManagerManagment.setBackground(Color.WHITE);
			lblTempMarketingManagerManagment.setBounds(0, 0, 451, 42);
		}
		return lblTempMarketingManagerManagment;
	}
	
	JLabel getLblMarketingManager() 
	{
		if (lblMarketingManager == null) 
		{
			lblMarketingManager = new JLabel("(Marketing Manager)");
			lblMarketingManager.setHorizontalAlignment(SwingConstants.CENTER);
			lblMarketingManager.setForeground(Color.RED);
			lblMarketingManager.setFont(new Font("David", Font.BOLD, 26));
			lblMarketingManager.setBackground(Color.WHITE);
			lblMarketingManager.setBounds(0, 40, 451, 42);
		}
		return lblMarketingManager;
	}

	
	JButton getBtnAudienceForTemp()
	{
		if (btnAudienceForTemp == null) 
		{
			btnAudienceForTemp = new JButton("Assign Customers For Template");
			btnAudienceForTemp.addActionListener(new BtnAudienceForTemplateActionListener());
			btnAudienceForTemp.setFont(new Font("Tahoma", Font.BOLD, 12));
			btnAudienceForTemp.setBounds(95, 193, 250, 42);
		}
		return btnAudienceForTemp;
	}

	JButton getBtnUpdateTemp()
	{
		if (btnUpdateTemp == null) 
		{
			btnUpdateTemp = new JButton("Update Template Details");
			btnUpdateTemp.addActionListener(new BtnUpdateTemplateActionListener());
			btnUpdateTemp.setFont(new Font("Tahoma", Font.BOLD, 12));
			btnUpdateTemp.setBounds(95, 87, 250, 42);
		}
		return btnUpdateTemp;
	}
	
	JButton getBtnChangeTempStatus()
	{
		if (btnChangeTempStatus == null) 
		{
			btnChangeTempStatus = new JButton("Change Templates status");
			btnChangeTempStatus.addActionListener(new BtnChangeTemplateStatusActionListener());
			btnChangeTempStatus.setFont(new Font("Tahoma", Font.BOLD, 12));
			btnChangeTempStatus.setBounds(95, 140, 250, 42);
		}
		return btnChangeTempStatus;
	}
	
	JButton getBtnBack() {
		if (btnBack == null) {
			btnBack = new JButton("Back");
			btnBack.addActionListener(new BtnQuitActionListener());
			btnBack.setFont(new Font("Tahoma", Font.BOLD, 12));
			btnBack.setBounds(156, 246, 124, 23);
		}
		return btnBack;
	}
	/**
	 * This inner class implements event listener for pressing Back button
	 * @author AL
	 *
	 */
	private class BtnQuitActionListener implements ActionListener 
	{
		public void actionPerformed(ActionEvent arg0) 
		{
			ClientStart.panelSwicher(new MarketingScreen());
		}
	}

	/**
	 * This inner class implements event listener for pressing "assign audience for Template" button
	 * @author AL
	 *
	 */
	private class BtnAudienceForTemplateActionListener implements ActionListener 
	{
		public void actionPerformed(ActionEvent arg0) 
		{
			if ((!ClientStart.user.getPosition().equals("Marketing Manager")))
				JOptionPane.showMessageDialog(null, "You are not authorized to do this action!", "Security Issue", JOptionPane.ERROR_MESSAGE);
			else {
				TemplateAssignCustomersScreen AssignCustTempScreen = new TemplateAssignCustomersScreen();
				ClientStart.panelSwicher(AssignCustTempScreen);
			}
		}
	}
	
	
	/**
	 * This inner class implements event listener for pressing "Update Template" button
	 * @author AL
	 *
	 */
	private class BtnUpdateTemplateActionListener implements ActionListener 
	{
		public void actionPerformed(ActionEvent arg0) 
		{
			if ((!ClientStart.user.getPosition().equals("Marketing Manager")))
			JOptionPane.showMessageDialog(null, "You are not authorized to do this action!", "Security Issue", JOptionPane.ERROR_MESSAGE);
		else {
			TemplateUpdateScreen UpdateTempScreen = new TemplateUpdateScreen();
			ClientStart.panelSwicher(UpdateTempScreen);
		}
		}
	}
	
	/**
	 * This inner class implements event listener for pressing "Change Template Status" button
	 * @author AL
	 *
	 */
	private class BtnChangeTemplateStatusActionListener implements ActionListener 
	{
		public void actionPerformed(ActionEvent arg0) 
		{
			if ((!ClientStart.user.getPosition().equals("Marketing Manager")))
			JOptionPane.showMessageDialog(null, "You are not authorized to do this action!", "Security Issue", JOptionPane.ERROR_MESSAGE);
		else {
			TemplateChangeStatusScreen ChngSttsTempScreen = new TemplateChangeStatusScreen();
			ClientStart.panelSwicher(ChngSttsTempScreen);
		}
		}
	}
}
